﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UIShare
{
    public static class MsgBox
    {
        private const string INFORMATION = "提示";
        private const string QUESTION = "询问";
        private const string ERROR = "错误";
        private const string WARNING = "警告";

        public static void Info(string text)
        {
            XtraMessageBox.Show(text, INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public static void Question(string text, Action yesAction, Action noAction)
        {
            DialogResult dialogResult = XtraMessageBox.Show(text, QUESTION, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            switch (dialogResult)
            {
                case DialogResult.No:
                    if (noAction != null)
                        noAction.Invoke();
                    break;
                case DialogResult.Yes:
                    if(yesAction != null)
                        yesAction.Invoke();
                    break;
                default:
                    break;
            }
        }

        public static void Question(string text, Action yesAction, Action noAction, Action cancelAction)
        {
            DialogResult dialogResult = XtraMessageBox.Show(text, QUESTION, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            switch (dialogResult)
            {
                case DialogResult.Cancel:
                    if (cancelAction != null)
                        cancelAction.Invoke();
                    break;
                case DialogResult.No:
                    if (noAction != null)
                        noAction.Invoke();
                    break;
                case DialogResult.Yes:
                    if (yesAction != null)
                        yesAction.Invoke();
                    break;
                default:
                    break;
            }
        }

        public static void Error(string text)
        {
            XtraMessageBox.Show(text, ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public static void Warning(string text)
        {
            XtraMessageBox.Show(text, WARNING, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
    }
}
